package com.atguigu.gmall.product.controller;

import com.atguigu.gmall.common.result.Result;
import com.atguigu.gmall.model.product.BaseTrademark;
import com.atguigu.gmall.product.service.BaseTradeMarkService;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.api.R;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/admin/product/baseTrademark")
//@CrossOrigin    //解决跨域
public class BaseTradeMarkController {

    //调用服务层
    @Autowired
    private BaseTradeMarkService baseTradeMarkService;

    @GetMapping("{page}/{limit}")
    public Result getTradeMarkPage(@PathVariable Long page,
                                   @PathVariable Long limit){
        //分页
        Page<BaseTrademark> baseTrademarkPage = new Page<>(page,limit);
        //调用服务层方法
        IPage iPage = baseTradeMarkService.getTradeMarkPage(baseTrademarkPage);
        return Result.ok(iPage);
    }

    //保存
    ///admin/product/baseTrademark/save
    @PostMapping("save")
    public Result saveTradeMark(@RequestBody BaseTrademark baseTrademark){
        //调用方法
         baseTradeMarkService.save(baseTrademark);
         return Result.ok();
    }

    //删除
//    /admin/product/baseTrademark/remove/{id}
    @DeleteMapping("remove/{id}")
    public Result removeById(@PathVariable Long id){
        //调用方法
        baseTradeMarkService.removeById(id);
        return Result.ok();
    }

    //根据id获取数据
    ///admin/product/baseTrademark/get/{id}
    @GetMapping("get/{id}")
    public Result getById(@PathVariable Long id){
        //调用方法
        BaseTrademark byId = baseTradeMarkService.getById(id);
        return Result.ok(byId);
    }

    //修改
    ///admin/product/baseTrademark/update
    @PutMapping("/update")
    public Result update(@RequestBody BaseTrademark baseTrademark){
        //调用方法
        baseTradeMarkService.updateById(baseTrademark);
        return Result.ok();
    }
}
